#include "pager.h"
#include "utils.h"
#include <assert.h>


void main(void) {
    __test_appendAndWriteOnePage("foo.db");
}

void __test_appendAndWriteOnePage(const char* name) {
    char c0 = 0x41; // 'A'
    char c1 = 0x33; // '3'
    pPageManager mgr = openFile(name);
    printPM(mgr);
    int pgno = appendPage(mgr);
    printf("pgno=%d\n", pgno);
    char* buf = obtainPage(mgr, pgno);
    startWritePage(mgr, pgno);
    buf[0] = c0;
    buf[1] = c1;
    flushPage(mgr, pgno);
    releasePage(mgr, pgno);

    //
    buf = obtainPage(mgr, pgno);
    assert(c0 == buf[0]);
    assert(c1 == buf[1]);
    // assert(1 == 2);
    closeFile(mgr);
}